<template>
	<view class="main">
		<view class="active_tit">
			<view class="tit">
				物流类
			</view>
			<!-- <view class="add">
				＋
			</view> -->
		</view>
		<!-- input -->
		<ActiveForm required ref='truckCount'>
			<view class="active_label">
				车辆数量：
			</view>
			<view class="active_input">
				<mInput :thousand='false' type="number" v-model="form.truckCount" />
			</view>
		</ActiveForm>

		<ActiveForm required ref='ownTruckCount'>
			<view class="active_label">
				自有车辆数：
			</view>
			<view class="active_input">
				<mInput :thousand='false' type="number" v-model="form.ownTruckCount" />
			</view>
		</ActiveForm>

		<ActiveForm required ref='empCount'>
			<view class="active_label">
				雇佣人数：
			</view>
			<view class="active_input">
				<mInput :thousand='false' type="number" v-model="form.empCount" />
			</view>
		</ActiveForm>

		<ActiveForm required ref='turnover12month'>
			<view class="active_label">
				近12个月营业额（元）：
			</view>
			<view class="active_input">
				<mInput maxlength="16" type="number" v-model="form.turnover12month" />
			</view>
		</ActiveForm>
		<ActiveForm required ref='invoiceRatio'>
			<view class="active_label">
				开票比例（%）：
			</view>
			<view class="active_input">
				<mInput :thousand='false' type="number" v-model="form.invoiceRatio" />
			</view>
		</ActiveForm>

		<ActiveForm required ref='ownTurnover12month'>
			<view class="active_label">
				自有车辆近12个月营业额（元）：
			</view>
			<view class="active_input">
				<mInput maxlength="16" type="number" v-model="form.ownTurnover12month" />
			</view>
		</ActiveForm>
		<ActiveForm required ref='marginRate'>
			<view class="active_label">
				综合毛利率（%）：
			</view>
			<view class="active_input">
				<mInput :thousand='false' type="number" v-model="form.marginRate" />
			</view>
		</ActiveForm>
		<ActiveForm required ref='turnoverLast12'>
			<view class="active_label">
				近13-24个月营业额（元）：
			</view>
			<view class="active_input">
				<mInput maxlength="16" type="number" v-model="form.turnoverLast12" />
			</view>
		</ActiveForm>
		<ActiveForm required ref='nextYearTurnover'>
			<view class="active_label">
				预计未来一年营业额（元）：
			</view>
			<view class="active_input">
				<mInput maxlength="16" type="number" v-model="form.nextYearTurnover" />
			</view>
		</ActiveForm>
		<view class="active_tit">
			<view class="tit2">
				自有车辆信息
			</view>
			<!-- <view class="add" @click="adds">
				＋
			</view> -->
		</view>

		<block v-for="(item,index) in carForm">
			<view class="cut">自有车辆{{index+1}} <uni-icons class="clear" type="clear" @click='stdDel(carForm,item,"stdOffsurTrafficOwner")'></uni-icons></view>
			<view class="main">
				<ActiveForm required ref=''>
					<view class="active_label">
						序号：
					</view>
					<view class="active_input">
						<input type="text" :disabled="true" v-model="item.xh" />
					</view>
				</ActiveForm>
				<ActiveForm required ref='truckType'>
					<view class="active_label">
						车辆类型：
					</view>
					<view class="active_input">
						<input type="text" :disabled="true" v-model="item.truckType" />
					</view>
				</ActiveForm>
				<ActiveForm required ref='tonnage'>
					<view class="active_label">
						吨位：
					</view>
					<view class="active_input">
						<mInput :thousand='false' type="number" v-model="item.tonnage" />
					</view>
				</ActiveForm>
				<ActiveForm required ref='buyTime'>
					<view class="active_label">
						购买时间：
					</view>
					<view class="active_input">
						<picker style="width: 100%;" mode="date" :value="item.buyTime"   @change="(o)=>{item.buyTime=o.target.value}">
						    <view >{{item.buyTime}}</view>
						</picker>
					</view>
				</ActiveForm>
				<ActiveForm required ref='buyPrice'>
					<view class="active_label">
						购买价格（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.buyPrice" />
					</view>
				</ActiveForm>
				<ActiveForm required ref='depreciationPrice'>
					<view class="active_label">
						折旧后价格（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.depreciationPrice" />
					</view>
				</ActiveForm>
				<ActiveForm required ref='license'>
					<view class="active_label">
						车牌号：
					</view>
					<view class="active_input">
						<input type="text" v-model="item.license" />
					</view>
				</ActiveForm>

			</view>
		</block>
		<view class="active_tit">
			<view class="" style="display: flex;">
				<view class="add" @click="adds">
					新增自有车
				</view>
			</view>
		</view>
		<view class="active_tit">
			<view class="tit2">
				主要货主方信息
			</view>
			<!-- <view class="add" @click="add">
				＋
			</view> -->
		</view>
		<block v-for="(item,index) in hzForm">
			<view class="cut">货主方客户{{index+1}} <uni-icons class="clear" type="clear" @click='stdDel(hzForm,item,"stdOffsurTrafficMainCargo")'></uni-icons></view>
			<view class="main">
				<ActiveForm required ref=''>
					<view class="active_label">
						序号：
					</view>
					<view class="active_input">
						<input type="text" :disabled="true" v-model="item.xh" />
					</view>
				</ActiveForm>
				<ActiveForm required ref='cargoOwner'>
					<view class="active_label">
						货主方：
					</view>
					<view class="active_input">
						<input type="text" v-model="item.cargoOwner" />
					</view>
				</ActiveForm>
				<ActiveForm required ref='settlementType'>
					<view class="active_label">
						运费结算方式：
					</view>
					<view class="active_input">
						<SelectPicker v-model="item.settlementType" :options="jsfs" placeholder="请选择" />
						<!-- <input type="text" v-model="item.settlementType" /> -->
					</view>
				</ActiveForm>
				<ActiveForm required ref='traQuotaRatio'>
					<view class="active_label">
						年运输额占比（%）：
					</view>
					<view class="active_input">
						<mInput :thousand='false' type="number" v-model="item.traQuotaRatio" />
					</view>
				</ActiveForm>
				<ActiveForm required ref='traQuota'>
					<view class="active_label">
						年运输额（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.traQuota" />
					</view>
				</ActiveForm>
				<ActiveForm required ref='traQuota'>
					<view class="active_label">
						账期（月）：
					</view>
					<view class="active_input">
						<mInput :thousand='false' type="number" v-model="item.accountPeriod" />
					</view>
				</ActiveForm>
				<ActiveForm required ref='traQuota'>
					<view class="active_label">
						详情：
					</view>
					<view class="active_input">
						<input  v-model="item.exComments" />
					</view>
				</ActiveForm>
			</view>
		</block>
		<view class="active_tit">
			<view class="" style="display: flex;">
				<view class="add" @click="add">
					新增货主方客户
				</view>
			</view>
		</view>
		<view class="active_tit">
			<view class="tit2">
				毛利率分析
			</view>
		</view>
		<block v-for="(item,index) in mllForm">
			<view class="main">
				<ActiveForm ref=''>
					<view class="active_label">
						运输类型：
					</view>
					<view class="active_input">
						<SelectPicker disabled v-model="item.trafficType" :options="option" placeholder="请选择" />
					</view>
				</ActiveForm>
				<ActiveForm  ref='turnoverYear'>
					<view class="active_label">
						年收入金额（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.turnoverYear" />
					</view>
				</ActiveForm>
				<ActiveForm  ref='oilCost'>
					<view class="active_label">
						年支付油费（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.oilCost" />
					</view>
				</ActiveForm>
				<ActiveForm  ref='insuranceCost'>
					<view class="active_label">
						年缴保险费（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.insuranceCost" />
					</view>
				</ActiveForm>
				<ActiveForm  ref='salaryCost'>
					<view class="active_label">
						年人工工资（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.salaryCost" />
					</view>
				</ActiveForm>
				<ActiveForm  ref='fixCost'>
					<view class="active_label">
						年维修费（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.fixCost" />
					</view>
				</ActiveForm>
				<ActiveForm  ref='affiliationCost'>
					<view class="active_label">
						挂靠费（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.affiliationCost" />
					</view>
				</ActiveForm>
				<ActiveForm  ref='marginRate' v-if="item.marginRate===NaN">
					<view class="active_label">
						毛利率（%）：
					</view>
					<view class="active_input">
						<input disabled :thousand='false' type="number"
                   :value="0"
                   @input="item.marginRate = $event.target.value"
            />
					</view>
				</ActiveForm>
				<ActiveForm  ref='marginRate' v-else>
					<view class="active_label">
						毛利率（%）：
					</view>
					<view class="active_input">
						<input disabled :thousand='false' type="number"
                   :value="calculateMarginRate(item)"
                   @input="item.marginRate = $event.target.value"
            />
					</view>
				</ActiveForm>
			</view>
		</block>
		<view class="main">
			<view class="active_tit">
				<view class="tit2">
					毛利率合计
				</view>
			</view>
			<ActiveForm  ref='turnoverYear'>
				<view class="active_label">
					年收入金额（元）：
				</view>
				<view class="active_input">
					<mInput disabled type="number" v-model="hjForm.turnoverYear" />
				</view>
			</ActiveForm>
			<ActiveForm  ref='oilCost'>
				<view class="active_label">
					年支付油费（元）：
				</view>
				<view class="active_input">
					<mInput disabled type="number" v-model="hjForm.oilCost" />
				</view>
			</ActiveForm>
			<ActiveForm  ref='insuranceCost'>
				<view class="active_label">
					年缴保险费（元）：
				</view>
				<view class="active_input">
					<mInput disabled type="number" v-model="hjForm.insuranceCost" />
				</view>
			</ActiveForm>
			<ActiveForm  ref='salaryCost'>
				<view class="active_label">
					年人工工资（元）：
				</view>
				<view class="active_input">
					<mInput disabled type="number" v-model="hjForm.salaryCost" />
				</view>
			</ActiveForm>
			<ActiveForm  ref='fixCost'>
				<view class="active_label">
					年维修费（元）：
				</view>
				<view class="active_input">
					<mInput disabled type="number" v-model="hjForm.fixCostHj" />
				</view>
			</ActiveForm>
			<ActiveForm  ref='affiliationCost'>
				<view class="active_label">
					挂靠费（元）：
				</view>
				<view class="active_input">
					<mInput disabled type="number" v-model="hjForm.affiliationCost" />
				</view>
			</ActiveForm>
			<ActiveForm  ref='marginRate'>
				<view class="active_label">
					毛利率合计（%）：
				</view>
				<view class="active_input">
					<mInput disabled type="number" v-model="hjForm.marginRate" />
				</view>
			</ActiveForm>
		</view>

	</view>
</template>

<script>
	import SelectPicker from "../../../SelectPicker";

  const calculateMarginRate = (item) => {
    const totalCost = Number(item.oilCost) + Number(item.insuranceCost) +
        Number(item.salaryCost) + Number(item.fixCost) +
        Number(item.affiliationCost)
    return ((1 - totalCost / Number(item.turnoverYear)) * 100).toFixed(2)
  }

	export default {
		name: 'activeForm',
		data() {
			return {
				province: "",
				city: "",
				county: "",
				index: 1,
				jsfs:[],
				hjForm: {
					turnoverYear:'',
					oilCost:'',
					insuranceCost:'',
					affiliationCost:'',
					salaryCost:'',
					fixCostHj:'',
					marginRate:''
				},
				hzForm: [],
				mllForm: [],
				carForm: [],
				form: {
					corCerttype: '',
					checked: '',

				},
				option: []
			}
		},
		components: {
			SelectPicker
		},
		computed: {
			

		},
		watch: {
			hzForm: {
				handler: function(res) {
					 this.jsfs=getApp().globalData.optType.SETTLE
					//console.warn('货主数据变化', res)
					getApp().globalData.stdOffsurTrafficMainCargo = res
				},
				deep: true
			},
			mllForm: {
				handler: function(res) {
					//console.warn('mllForm数据变化', res)
					getApp().globalData.stdOffsurTrafficMargin = res
					//计算合计
					if(this.mllForm.length==2){
						this.hjForm.turnoverYear = Number(this.mllForm[0].turnoverYear) +Number(this.mllForm[1].turnoverYear)
						this.hjForm.oilCost = Number(this.mllForm[0].oilCost) +Number(this.mllForm[1].oilCost)
						this.hjForm.insuranceCost = Number(this.mllForm[0].insuranceCost) +Number(this.mllForm[1].insuranceCost)
						this.hjForm.affiliationCost = Number(this.mllForm[0].affiliationCost) +Number(this.mllForm[1].affiliationCost)
						this.hjForm.salaryCost = Number(this.mllForm[0].salaryCost) +Number(this.mllForm[1].salaryCost)
						this.hjForm.fixCostHj = Number(this.mllForm[0].fixCost) +Number(this.mllForm[1].fixCost)
						this.hjForm.marginRate = ((1-(this.hjForm.oilCost+this.hjForm.insuranceCost+this.hjForm.affiliationCost+this.hjForm.salaryCost+this.hjForm.fixCostHj)/this.hjForm.turnoverYear)*100).toFixed(2)
						//this.hjForm.marginRate = ((Number(this.mllForm[0].turnoverYear)/this.hjForm.turnoverYear*Number(this.mllForm[0].marginRate))+(Number(this.mllForm[1].turnoverYear)/this.hjForm.turnoverYear*Number(this.mllForm[1].marginRate))).toFixed(2)
						//console.log(this.hjForm.fixCostHj,this.hjForm.salaryCost,this.hjForm.affiliationCost,this.hjForm.insuranceCost,this.hjForm.oilCost,this.hjForm.turnoverYear,this.hjForm.marginRate)
						if(this.hjForm.marginRate=='NaN'||this.hjForm.marginRate==='-Infinity'){
							this.hjForm.marginRate = 0
						}
						
						getApp().globalData.total.stdOffsurTrafficMargin = this.hjForm
						
					}
					
				},
				deep: true
			},
			carForm: {
				handler: function(res) {
					//console.warn('carForm数据变化', res)
					getApp().globalData.stdOffsurTrafficOwner = res
				},
				deep: true
			},
			form: {
				handler: function(res) {
					//console.warn('form数据变化', res)
					getApp().globalData.stdOffsurTraffic = res
				},
				deep: true
			}
		},
		mounted() {
			//获取返显数据
			setTimeout(() => {
				this.option = getApp().globalData.optType.TRA_TYPE
				//数据反显
				this.form = getApp().globalData.stdOffsurTraffic
				this.carForm = getApp().globalData.stdOffsurTrafficOwner
				this.mllForm = getApp().globalData.stdOffsurTrafficMargin
			
				this.hzForm = getApp().globalData.stdOffsurTrafficMainCargo

			}, getApp().globalData.timeout)
		},
		methods: {
			add() {
				this.hzForm.push({xh:this.hzForm.length+1})
			},
			adds() {
				this.carForm.push({truckType:'自营',xh:this.carForm.length+1,'buyTime':''})
			}
		}
	}
</script>

<style lang="scss">


</style>
